
/**
*天馈  js
*/ 

var	antennafeederDS;
var antennafeederFormPanel;
function doAntennaFeederDelete(id)
{
	Ext.MessageBox.confirm('确认删除', '确认删除该信息?', 
	function(btn) {
		if(btn == 'yes') // 选中了是按钮	
		{
			JAntennaFeederWeb.deleteAntennaFeederBO(id,function(data)
			{
				if(data)
				{ 
					Ext.Msg.alert('成功',"操作成功！"); 
					antennafeederDS.load({params:{start:0,limit:17,'<%=Constant.BTS_CODE%>':'<%=strbtscode%>'}});	 
					//antennafeederFormPanel.getForm().reset();			
				}else
				{
					Ext.Msg.alert("失败","操作失败!");
				}
			})
		}
	})	
}


Ext.onReady(function(){  
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';

	var antennafeederType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'btscode', type: "string"},
							   {name: 'btsname', type: "string"},
							   {name: 'antennaT', type: "string"},
							   {name: 'antennaM', type: "string"},
							   {name: 'antennaNum', type: "string"},
							   {name: 'antennaPlu',  type: 'string'},
							   {name: 'antennaDir', type: "string"},
							   {name: 'antennaPT', type: "string"},
							   {name: 'antennaFB', type: 'string'},
							   {name: 'antennaH', type: 'string'},
							   {name: 'antennaCRD',  type: 'string'},
							   {name: 'magnifierT',  type: 'string'},
							   {name: 'magnifierM',  type: 'string'},
							   {name: 'magnifierNum',  type: 'string'},
							   {name: 'magnifierCell',  type: 'string'},
							   {name: 'magnifierCRD',  type: 'string'},
							   {name: 'feederT',  type: 'string'},
							   {name: 'feederM',  type: 'string'},
							   {name: 'feederLen',  type: 'string'},
							   {name: 'feederNum',  type: 'string'},
							   {name: 'maintenance',  type: 'string'},
							   {name: 'refreshtime',  type: 'date'},
							   {name: 'memo',  type: 'string'},
							   {name: 'anteIsMakeAng',  type: 'string'},
							   {name: 'anteDicAng',  type: 'string'},
							   {name: 'anteUpAng',  type: 'string'}
						 ]); 
	var antennafeederCM = new Ext.grid.ColumnModel(
			[
				new Ext.grid.CheckboxSelectionModel({singleSelect: true}), 	            
				{header: "流水号", sortable: true, dataIndex: 'id',align:'left'},
				{header: "基站编号", sortable: true, dataIndex: 'btscode',align:'left'},
				{header: "基站名称",  sortable: true, dataIndex: 'btsname',align:'left'},	
				{header: "型号",  sortable: true, dataIndex: 'antennaT',align:'left'},	 
				{header: "厂家",  sortable: true, dataIndex: 'antennaM',align:'left'},	 	
				{header: "数量",  sortable: true, dataIndex: 'antennaNum',align:'left'},	 	
				{header: "增益",  sortable: true, dataIndex: 'antennaPlu',align:'left'},	 	
				{header: "使用频段",  sortable: true, dataIndex: 'antennaFB',align:'left'},	 					
				{header: "删除", dataIndex: 'id',renderer: showDelete}					
			]
		);				 
	
	function showDelete(id)
	{
		return "<input type='button' value='删除' class='x-btn button' onclick='doAntennaFeederDelete(\"" + id  +   "\")'>";  
	}
	
	
	
	antennafeederDS = new Ext.data.Store({
				proxy: new Ext.data.DWRProxy(JAntennaFeederWeb.getAntennaFeederList, true),	
				reader: new Ext.data.ListRangeReader({
					totalProperty: 'totalSize',
					id: 'id'
				}, antennafeederType),
				sortInfo:{field:'id', direction:'ASC'}// 排序信息
			});

	
	var towerMountedGridDiv = Ext.get("mainTabPanelDIV");
	var antennafeederGrid = new Ext.grid.GridPanel({			 	
			ds: antennafeederDS,
			cm: antennafeederCM, 
			sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) {
                            antennafeederFormPanel.getForm().loadRecord(rec);
                        }
                    }
                }),
			autoWidth : true,  
			autoScroll : true,  
			autoHeight　: false,
			region : 'center',
			height: 400,
			minSize: 200,		
			frame:true,
			collapsible:false, 
			enableDragDrop:false, 		
			bbar: new Ext.PagingToolbar({
					pageSize: 17,
					store: antennafeederDS,
					displayInfo: true,
					displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
					emptyMsg: "没有记录"
				})
		});

	antennafeederDS.on('load', function() {
		antennafeederGrid.getSelectionModel().selectFirstRow(); 
	});		
		
	var antennaDirStore  = new Ext.data.Store({  
			proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
			reader:new Ext.data.DWRArrayReader(
					{},
					new Ext.data.Record.create([  
						{name: 'text', mapping:1},       
						{name: 'value',mapping:0}                   
					  ])
					)  
		});
	var antennaDirCombo = new Ext.form.ComboBox({	   
		fieldLabel: '方向性',
		name: 'antennaDir',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true, 
		hiddenName:'antennaDir',
		triggerAction: 'all', 
		editable:false, 
		store: antennaDirStore
	});
	antennaDirStore.on('beforeload', function() {
			  antennaDirStore.baseParams = {
					DIRECTORY_TYPE:'11'   
			  };
		});	
	antennaDirStore.load({params:{DIRECTORY_TYPE:'11'}});	
	
	
	var antennaPTStore  = new Ext.data.Store({  
			proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
			reader:new Ext.data.DWRArrayReader(
					{},
					new Ext.data.Record.create([  
						{name: 'text', mapping:1},       
						{name: 'value',mapping:0}                   
					  ])
					)  
		});
	var antennaPTCombo = new Ext.form.ComboBox({	   
		fieldLabel: '极化方式',
		name: 'antennaPT',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true, 
		hiddenName:'antennaPT',
		triggerAction: 'all', 
		editable:false, 
		store: antennaPTStore
	});
	antennaPTStore.on('beforeload', function() {
			  antennaPTStore.baseParams = {
					DIRECTORY_TYPE:'12'   
			  };
		});	
	antennaPTStore.load({params:{DIRECTORY_TYPE:'12'}});
	

	var antennaFBStore  = new Ext.data.Store({  
			proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
			reader:new Ext.data.DWRArrayReader(
					{},
					new Ext.data.Record.create([  
						{name: 'text', mapping:1},       
						{name: 'value',mapping:0}                   
					  ])
					)  
		});
	var antennaFBCombo = new Ext.form.ComboBox({	   
		fieldLabel: '使用频段',
		name: 'antennaFB',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true, 
		hiddenName:'antennaFB',
		triggerAction: 'all', 
		editable:false, 
		store: antennaFBStore
	});
	antennaFBStore.on('beforeload', function() {
			  antennaFBStore.baseParams = {
					DIRECTORY_TYPE:'13'   
			  };
		});	
	antennaFBStore.load({params:{DIRECTORY_TYPE:'13'}});	
	
	
	var anteIsMakeAngStore  = new Ext.data.Store({  
			proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
			reader:new Ext.data.DWRArrayReader(
					{},
					new Ext.data.Record.create([  
						{name: 'text', mapping:1},       
						{name: 'value',mapping:0}                   
					  ])
					)  
		});
	var anteIsMakeAngCombo = new Ext.form.ComboBox({	   
		fieldLabel: '是否美化视角',
		name: 'anteIsMakeAng',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true, 
		hiddenName:'anteIsMakeAng',
		triggerAction: 'all', 
		editable:false, 
		store: anteIsMakeAngStore
	});
	anteIsMakeAngStore.on('beforeload', function() {
			  anteIsMakeAngStore.baseParams = {
					DIRECTORY_TYPE:'06'   
			  };
		});	
	anteIsMakeAngStore.load({params:{DIRECTORY_TYPE:'06'}});
	
	
	var anteDicAngStore  = new Ext.data.Store({  
			proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
			reader:new Ext.data.DWRArrayReader(
					{},
					new Ext.data.Record.create([  
						{name: 'text', mapping:1},       
						{name: 'value',mapping:0}                   
					  ])
					)  
		});
	var anteDicAngCombo = new Ext.form.ComboBox({	   
		fieldLabel: '方向角',
		name: 'anteDicAng',	
		width:100,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true, 
		hiddenName:'anteDicAng',
		triggerAction: 'all', 
		editable:false, 
		store: anteDicAngStore
	});
	anteDicAngStore.on('beforeload', function() {
			  anteDicAngStore.baseParams = {
					DIRECTORY_TYPE:'28'   
			  };
		});	
	anteDicAngStore.load({params:{DIRECTORY_TYPE:'28'}});
	
	// Setup the form panel
	antennafeederFormPanel = new Ext.form.FormPanel({
		region     : 'south', 
		bodyStyle  : 'padding: 10px; background-color: #DFE8F6',  
		height: 250,
		minSize: 250,
		maxSize: 350,
		frame:true,
		buttonAlign:'right',
		layout:'column', 
		items:[
			{
				layout:'column', 
				items:[
					 {
						columnWidth:.50,
						layout: 'form',  
						labelWidth:70,	 
						labelAlign:'right',	
						items: [
							{
								xtype:'hidden',
								fieldLabel: '流水号',
								width:250,
								name: 'id'
							}, {
								xtype:'textfield', 
								fieldLabel: '基站编号', 
								width:250,
								name: 'btscode'
							}]
					 },
					 {
						columnWidth:.50,
						layout: 'form',  
						labelAlign:'right',	
						labelWidth:70,	 
						items: [
							{ 
								xtype:'textfield',
								fieldLabel: '基站名称',
								width:250,
								readOnly: true,
								name: 'btsname'
							}]
					 }
				]
			},
			{
				xtype:'tabpanel',
				plain:true,
				activeTab: 0,
				height:160, 
				deferredRender: false,
				defaults:{bodyStyle:'padding:10px'},
				items:[
					{
						title:'天线类数据',
						frame:true,
						labelAlign:'right',
						layout:'column', 
						items:[
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	
								labelAlign:'right',		
								items: [
									{
										xtype:'textfield', 
										fieldLabel: '型号', 										
										width:100,
										name: 'antennaT'
									},antennaDirCombo
									,{
										xtype:'textfield', 
										fieldLabel: '扩容及维修更换记录', 										
										width:100,
										name: 'antennaCRD'
									}
									]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelAlign:'right',	
								labelWidth:90,	 
								items: [
									{
										xtype:'textfield',
										fieldLabel: '厂家',
										width:100,
										name: 'antennaM'
									},
									antennaPTCombo,
									anteIsMakeAngCombo
									]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelAlign:'right',	
								labelWidth:70,	 
								items: [
									{
										xtype:'numberfield',
										value:1,
										fieldLabel: '数量',
										width:100, 
										name: 'antennaNum'
									},antennaFBCombo,
									anteDicAngCombo
									]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	
								labelAlign:'right',		
								items: [
									{
										xtype:'textfield',
										fieldLabel: '增益',
										width:100, 
										name: 'antennaPlu'
									},{
										xtype:'numberfield',
										value:1,
										decimalPrecision:1,
										fieldLabel: '挂高（米）',
										width:100, 
										name: 'antennaH'
									},{
										xtype:'textfield',
										fieldLabel: '俯仰角',
										width:100, 
										name: 'anteUpAng'
									}]
							 }
						]
					},{
						title:'塔顶放大器类数据',
						frame:true,
						layout:'column', 
						labelAlign :'right',
						items:[
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	 
								labelAlign:'right',	
								items: [
									{
										xtype:'textfield', 
										fieldLabel: '规格型号', 
										width:100,
										name: 'magnifierT'
									},{
										xtype:'textfield', 
										fieldLabel: '更换记录', 
										width:100,
										name: 'magnifierCRD'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	 
								labelAlign:'right',	
								items: [
									{
										xtype:'textfield',
										fieldLabel: '厂家',
										width:100,
										name: 'magnifierM'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:90,
								labelAlign:'right',		
								items: [
									{
										xtype:'numberfield',
										value:1, 
										fieldLabel: '数量',
										width:100,
										name: 'magnifierNum'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	
								labelAlign:'right',		
								items: [
									{
										xtype:'textfield',
										fieldLabel: '放大小区信号',
										width:100,
										name: 'magnifierCell'
									}]
							 }
						]
					},{
						title:'馈线数据',
						frame:true,
						layout:'column', 
						labelAlign :'right',
						items:[
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	 
								labelAlign:'right',	
								items: [
									{
										xtype:'textfield', 
										fieldLabel: '型号', 
										width:100,
										name: 'feederT'
									},{
										xtype:'textfield', 
										fieldLabel: '扩容及更换记录', 
										width:100,
										name: 'maintenance'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	
								labelAlign:'right',		
								items: [
									{
										xtype:'textfield',
										fieldLabel: '厂家',
										width:100,
										name: 'feederM'
									},{
										xtype:'textarea',
										fieldLabel: '备注',
										width:100,
										name: 'memo'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	
								labelAlign:'right',		
								items: [
									{
										xtype:'numberfield',
										value:1,
										decimalPrecision:1,
										fieldLabel: '长度（米）',
										width:100,
										value:1,
										name: 'feederLen'
									}]
							 },
							 {
								columnWidth:.25,
								layout: 'form',  
								labelAlign:'right',	
								labelWidth:70,	 
								items: [
									{
										xtype:'numberfield',
										value:1, 
										fieldLabel: '数量',
										width:100,
										value:1,
										name: 'feederNum'
									}]
							 }
						]
					}]
			}	 
			],
		buttons :[
			{
				text : ' 保存',
				handler : saveAntennafeeder
			},{
				text : ' 新建/取消',
				handler : function(){
					antennafeederFormPanel.getForm().reset(); 
					antennafeederFormPanel.getForm().loadRecord(recordForAll);	
				}
			}
			]	
	});



	//Simple 'border layout' panel to house both grids
	
	var displayPanel = new Ext.Panel({
		width    : towerMountedGridDiv.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'antennafeederTab',
		items    : [
			antennafeederGrid,
			antennafeederFormPanel
		]
	});
	
	
	function saveAntennafeeder()
	{
		if (!antennafeederFormPanel.getForm().isValid())
			return;	
			
		var form = antennafeederFormPanel.getForm().getValues(false);	
		var ABO = {};
		ABO.id = form.id;
		ABO.btscode = form.btscode;
		ABO.btsname= form.btsname;
		ABO.antennaT = form.antennaT;		
		ABO.antennaM = form.antennaM;
		ABO.antennaNum = form.antennaNum;
		ABO.antennaPlu = form.antennaPlu;
		ABO.antennaDir = form.antennaDir;
		ABO.antennaPT = form.antennaPT;
		ABO.antennaFB = form.antennaFB;
		ABO.antennaH = form.antennaH; 
		ABO.antennaCRD = form.antennaCRD;
		ABO.magnifierT = form.magnifierT; 
		ABO.magnifierM = form.magnifierM; 
		ABO.magnifierNum = form.magnifierNum; 
		ABO.magnifierCell = form.magnifierCell; 
		ABO.magnifierCRD = form.magnifierCRD; 
		ABO.feederT = form.feederT; 
		ABO.feederM = form.feederM; 	
		ABO.feederLen = form.feederLen; 
		ABO.feederNum = form.feederNum; 
		ABO.maintenance = form.maintenance; 
		ABO.refreshtime = form.refreshtime;
		ABO.memo = form.memo; 
		ABO.anteIsMakeAng = form.anteIsMakeAng; 
		ABO.anteDicAng = form.anteDicAng; 
		ABO.anteUpAng = form.anteUpAng;  
			
		JAntennaFeederWeb.saveAntennaFeederBO(ABO,function(data)
		{
			if(data)
			{ 
				Ext.Msg.alert('成功',"操作成功！"); 
				loadDate(antennafeederDS,antennafeederFormPanel);		 
			}else
			{
				Ext.Msg.alert("失败","操作失败!");
			}
		})
			
	}
	
	loadDate(antennafeederDS,antennafeederFormPanel);	
	
})